const { findAllEvents, findAllRecord } = require('../dao/sportDao');
const calculate = require('../algorithm/calculate');

exports.getGroupScores = async function (req, res, next) {
    const events = await findAllEvents();
    let men = events.filter((event) => {
        if (event.gender == "男子") {
            return event;
        }
    });
    let women = events.filter((event) => {
        if (event.gender == "女子") {
            return event;
        }
    });
    const records = findAllRecord();
    const all_race = calculate(events, records);
    const men_race = calculate(men, records);
    const women_race = calculate(women, records);

    res.json({
        all: all_race,
        men: men_race,
        women: women_race
    });
}